<template>
  <div class="body1" style="padding-top:10px;">
    <div class="form_select">
      <div>
          <el-input class="select_input" size="small" v-model="form.name" placeholder="产品名称"></el-input>
          <el-select class="select_option" size="small" v-model="form.type" placeholder="产品分类">
            <el-option
              v-for="item in cate"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
          <el-button type="primary"  size="small" @click="getList">搜索</el-button>
      </div>
      <div class="select_right">
          <el-button type="primary" size="small" @click="exportExcel">导出excel</el-button>
          <el-button type="primary"
          size="small" @click="dialog('goodsCheck')">仓库盘点</el-button>
          <el-button type="primary" size="small" @click="dialog('addGoods')">+新增产品</el-button>
      </div>
    </div>
    <goodsTable :list="list" @func="dialogClose"></goodsTable>
    <addGoods :show="addGoodsShow" @func="dialogClose"></addGoods>
    <editGoods :show="editGoodsShow" :form="editGoods" @func="dialogClose"></editGoods>
    <goodsCheck :show="goodsCheckShow" :list="list"  @func="dialogClose"></goodsCheck>
    </div>
   </div>
</template>
 
<script>
import addGoods from "./addGoods"
import editGoods from "./editGoods"
import goodsTable from "./goodsTable"
import goodsCheck from "./goodsCheck"
import {excelExport} from "../../public/excelExport"
export default {
  name: "Goods",
  data() {
    return {
      list:[],
      form:{},
      cate:[
        {id:0,name:'全部'},
        {id:1,name:'院线产品'},
        {id:2,name:'家居产品'}
      ],
      editGoods:{},
      addGoodsShow:false,
      editGoodsShow:false,
      goodsCheckShow:false
    };
  },
  components: {
    "addGoods": addGoods,
    "editGoods": editGoods,
    "goodsTable": goodsTable,
    "goodsCheck":goodsCheck
  },
  created: function() {
    this.getList()
  },
  methods: {
    getList:function() {
      this.form.oa_id = localStorage.getItem('oa_id')
      var that = this
      this.$get('pc/goods/all',this.form).then((res) => {
        that.list = res.data
      })
    },
    dialog:function(key){
      this[key+'Show'] = !this[key+'Show']
    },
    dialogClose:function(data){
      this[data.key+'Show'] = !this[data.key+'Show']
      if(data.type){
        this.getList()
      }
      if(data.item){
        this[data.key] = data.item
      }
    },
    exportExcel:function() {
      let title = '商品信息表'
      excelExport(title)
      return false;
    }
}
};
</script>
<style>
</style>